<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>readfi</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="readf.html" title="readf" />
    <link rel="next" href="readk.html" title="readk" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">readfi</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="readf.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="readk.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="readfi"></a>
      <div class="titlepage"></div>
      <a id="IndexReadfi" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">readfi</span>
        </h2>
        <p>readfi — 
      Read a line of text from an external file.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141392944"></a>
        <h2>Description</h2>
        <p>
      Read a line of text from an external file once on initialisation.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141394224"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">Sres, iline <span class="command"><strong>readfi</strong></span> ifilname</pre>
      </div>
      <div class="refsect1">
        <a id="idp141455280"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>ifilname</em></span> -- an integer N denoting a file named "input.N" or a character string (in double quotes, spaces permitted) denoting the external file name. For a string, it may either be a full path name with directory specified or a simple filename.  In the later case, the file is sought first in the current directory, then in SSDIR, and finally in SFDIR.
    </p>
        <p>
      <span class="emphasis"><em>iline</em></span> -- line number, or -1 when end of file has been reached. 
    </p>
        <p>
      <span class="emphasis"><em>Sres</em></span> -- output of the line read from <span class="emphasis"><em>ifilname</em></span>.
    </p>
        <p>
      This opcode allows a line of text to be read from a named
      external file.  There may be any number of
      <span class="emphasis"><em>readfi</em></span> opcodes in an instrument or orchestra
      but they read separately from the same or different files.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141460368"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the readfi opcode. It uses the file <a class="ulink" href="examples/readfi.csd" target="_top"><em class="citetitle">readfi.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp141462224"></a>
          <p class="title">
            <strong>Example 741. Example of the readfi opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-n
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="oblock">instr</span> 1
    Swd <span class="opc">pwd</span>
        <span class="opc">printf_i</span> "Working directory is '<span class="op">%</span>s'\n", 1, Swd
        <span class="opc">prints</span> "Reading myself <span class="op">=</span>)<span class="op">:</span>\n"
<span class="olabel">read</span><span class="op">:</span>
Sline, iLineNum <span class="opc">readfi</span> "readfi.csd"
        <span class="opc">printf_i</span>  "Line <span class="op">%</span>d<span class="op">:</span> <span class="op">%</span>s", iLineNum, iLineNum, Sline
        <span class="octrl">if</span> iLineNum <span class="op">!=</span> <span class="op">-</span>1 <span class="octrl">igoto</span> <span class="olabel">read</span>
<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span>1 0 0.1
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141466512"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="readf.html" title="readf"><em class="citetitle">readf</em></a>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141468592"></a>
        <h2>Credits</h2>
        <p>John ffitch and Joachim Heintz</p>
        <p>2012; new in 5.17.12</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="readf.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="readk.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">readf </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> readk</td>
        </tr>
      </table>
    </div>
  </body>
</html>
